﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout_lay_admin.cshtml";
}
<style>
    body {
        background-color: #ffffff;
    }
</style>

<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">角色名称</label>
        <div class="layui-input-block">
            <input type="text" id="Role_Name" name="Role_Name" lay-verify="required" lay-reqtext="角色名称不能为空" placeholder="请输入角色名称" value="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">角色编码</label>
        <div class="layui-input-block">
            <input type="text" name="Role_Code" placeholder="请输入角色编码" value="" autocomplete="off" class="layui-input">
        </div>
    </div>

    @*<div class="layui-form-item">
            <label class="layui-form-label required">超级管理员</label>
            <div class="layui-input-block">
                <input type="radio" name="User_Sex" value="是" title="否" checked="">
                <input type="radio" name="User_Sex" value="是" title="否">
            </div>
        </div>*@
    <div class="layui-form-item">
        <label class="layui-form-label required">分组</label>
        <div class="layui-input-block">
            <select id="Role_GroupId" name="Role_GroupId" lay-search="">
            </select>
            @*<input type="text" id="Role_GroupId" name="Role_GroupId" placeholder="请输入角色编码" value="" autocomplete="off" class="layui-input">*@
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea name="Role_Remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script>
    //$(function () {

    //})

    var form;
    var formrender = function () {
        window.form.render('select');
    }

    layui.use(['form'], function () {
        window.form = layui.form;
        var layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                url: '/Base_Role/Create',
                type: 'post',
                dataType: 'text',
                data: data.field,
                success: function (resp) {
                    var json = eval('(' + resp + ')');
                    var index = layer.alert(json.Message, function () {
                        // 关闭弹出层
                        layer.close(index);
                        var saveid = json.data;
                        var callbacknode = { NodeName: data.field.Role_Name, id: saveid, forbidadd: true };                        
                        parent.addnoewfunction(callbacknode);                        
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                },
                error: function (resp) {
                    layer.alert("对不起出错了");
                }
            });
            return false;
        });

        $.ajax({
            type: "GET",
            url: '/Base_RoleGroup/SearchAll',
            dataType: 'json',
            success: function (data) {
                $('#Role_GroupId').empty();
                //selected="selected"
                var selected = GetQueryString("groupselect");
                for (var i = 0; i < data.length; i++) {
                    var option = "";
                    if (selected == data[i].BG_Id) {
                        option = '<option value="' + data[i].BG_Id + '" selected="selected" >' + data[i].BG_Name + '</option>';
                    } else {
                        option = '<option value="' + data[i].BG_Id + '" >' + data[i].BG_Name + '</option>';
                    }

                    $('#Role_GroupId').append(option);
                }
                form.render('select');
            }
        });

    });
</script>



